#region License
///License Begin
///This program has been developed by: Rodolfo Grave de Peralta, 
///Copyright (C) 2007 Rodolfo Grave de Peralta
///This program is free software; you can redistribute it and/or modify
///it under the terms of the GNU General Public License as published by
///the Free Software Foundation; either version 2 of the License, or
///(at your option) any later version.
///
///This program is distributed in the hope that it will be useful,
///but WITHOUT ANY WARRANTY; without even the implied warranty of
///MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
///GNU General Public License for more details.
///
///You should have received a copy of the GNU General Public License
///along with this program; if not, write to the Free Software
///Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
///License End
#endregion

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace TEAM.TimeTracking.Model
{
    public class Project : INotifyPropertyChanged
    {

        public Project()
        {
            tasks = new ObservableCollection<Task>();
        }

        protected string name;

        public string Name
        {
            get { return name; }
            set 
            { 
                name = value;
                OnPropertyChanged("Name");
            }
        }

        protected bool isActive;

        public bool IsActive
        {
            get { return isActive; }
            set 
            { 
                isActive = value;
                OnPropertyChanged("IsActive");
            }
        }

        protected ObservableCollection<Task> tasks;
        protected ReadOnlyObservableCollection<Task> readonlyTasks;

        public ReadOnlyObservableCollection<Task> Tasks
        {
            get 
            {
                if (readonlyTasks == null)
                {
                    readonlyTasks = new ReadOnlyObservableCollection<Task>(tasks);
                }
                return readonlyTasks; 
            }
        }

        public void AddTask(Task t)
        {
            if (t != null)
            {
                tasks.Add(t);
                t.ParentProject = this;
            }
            OnPropertyChanged("Tasks");
        }

        public void RemoveTask(Task t)
        {
            if (t != null)
            {
                tasks.Remove(t);
                t.ParentProject = null;
            }
            OnPropertyChanged("Tasks");
        }

        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #region Miembros de INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
